<template>
  <el-dialog v-model="dialogFormVisible" title="千峰教育管理系统" width="300" center>
    <el-form :model="form">
      <el-form-item label="管理员用户名" label-width="100px">
        <el-input v-model="form.adminname" autocomplete="off" />
      </el-form-item>
      <el-form-item label="管理员密码" label-width="100px">
        <el-input v-model="form.password" autocomplete="off" />
      </el-form-item>
      <el-form-item label="角色" label-width="100px">
        <el-input v-model="form.role" autocomplete="off" />
      </el-form-item>
      <el-form-item label="checkedKeys" label-width="100px">
        <el-input v-model="form.checkedKeys" autocomplete="off" />
      </el-form-item>
    </el-form>
    <template #footer>
      <div class="dialog-footer">
        <el-button @click="dialogFormVisible = false">重置</el-button>
        <el-button type="primary" @click="RegisterFn">注册</el-button>
      </div>
    </template>
  </el-dialog>
</template>
<script setup lang="ts">
import { reactive, ref } from 'vue'
import { useRouter } from 'vue-router'
import { UserRegisterReq } from '@/api/login'
import { ElMessage } from 'element-plus'

const router = useRouter()
const dialogFormVisible = ref(true)

const form = reactive({
  adminname: '',
  password: '',
  role: '',
  checkedKeys: ''
})
function RegisterFn() {
  console.log(form)
  UserRegisterReq(form).then((res) => {
    console.log(res.data)
    if (res.data.code == 200) {
      ElMessage.success(res.data.message)
      router.push('/login')
    } else if (res.data.code == 10004) {
      ElMessage.warning(res.data.message)
      router.push('/login')
    } else {
      ElMessage.error(res.data.message)
    }
  })
}
</script>
<style lang="scss" scoped></style>
